or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

component-integration.mdconstraint-configuration.mdindex.mdlayout-management.md

component-integration.mddocs/

0

# Component Integration

1

2

Component wrapper system providing seamless integration between Swing components and the MiGLayout constraint system. These classes bridge the gap between Swing's component model and MiGLayout's internal layout engine.

3

4

## Capabilities

5

6

### SwingComponentWrapper

7

8

Wrapper for individual Swing components to integrate with the MiGLayout constraint system.

9

10

```java { .api }

11

/**

12

* Component wrapper for individual Swing components.

13

* Implements ComponentWrapper to provide MiGLayout integration.

14

*/

15

public class SwingComponentWrapper implements ComponentWrapper {

16

17

/**

18

* Creates wrapper for Component.

19

* @param c The Swing component to wrap.

20

*/

21

public SwingComponentWrapper(Component c);

22

23

/**

24

* Returns the baseline for the specified width and height.

25

* @param width The width to get the baseline for. Use -1 to use current width.

26

* @param height The height to get the baseline for. Use -1 to use current height.

27

* @return The baseline or -1 if this component does not have a reasonable baseline.

28

*/

29

public final int getBaseline(int width, int height);

30

31

/**

32

* Returns the wrapped component.

33

* @return The wrapped Swing component.

34

*/

35

public final Object getComponent();

36

37

/**

38

* Returns the pixel unit conversion factor.

39

* @param isHor If the factor is for horizontal or vertical.

40

* @return The factor to multiply with an inch, point or millimeter to get pixels.

41

*/

42

public final float getPixelUnitFactor(boolean isHor);

43

}

44

```

45

46

### Component Positioning and Sizing

47

48

Methods for getting and setting component bounds and size information.

49

50

```java { .api }

51

/**

52

* Returns the current x coordinate of the component.

53

* @return The x coordinate.

54

*/

55

public final int getX();

56

57

/**

58

* Returns the current y coordinate of the component.

59

* @return The y coordinate.

60

*/

61

public final int getY();

62

63

/**

64

* Returns the current height of the component.

65

* @return The height.

66

*/

67

public final int getHeight();

68

69

/**

70

* Returns the current width of the component.

71

* @return The width.

72

*/

73

public final int getWidth();

74

75

/**

76

* Returns the screen location x coordinate.

77

* @return The screen x coordinate.

78

*/

79

public final int getScreenLocationX();

80

81

/**

82

* Returns the screen location y coordinate.

83

* @return The screen y coordinate.

84

*/

85

public final int getScreenLocationY();

86

87

/**

88

* Sets the bounds of the component.

89

* @param x The x coordinate.

90

* @param y The y coordinate.

91

* @param width The width.

92

* @param height The height.

93

*/

94

public final void setBounds(int x, int y, int width, int height);

95

96

/**

97

* Returns if the component is visible.

98

* @return True if visible.

99

*/

100

public boolean isVisible();

101

```

102

103

### Size Calculation Methods

104

105

Methods for calculating minimum, preferred, and maximum sizes.

106

107

```java { .api }

108

/**

109

* Returns the minimum height for the specified width.

110

* @param sz The size hint or -1 for no hint.

111

* @return The minimum height.

112

*/

113

public final int getMinimumHeight(int sz);

114

115

/**

116

* Returns the minimum width for the specified height.

117

* @param sz The size hint or -1 for no hint.

118

* @return The minimum width.

119

*/

120

public final int getMinimumWidth(int sz);

121

122

/**

123

* Returns the preferred height for the specified width.

124

* @param sz The size hint or -1 for no hint.

125

* @return The preferred height.

126

*/

127

public final int getPreferredHeight(int sz);

128

129

/**

130

* Returns the preferred width for the specified height.

131

* @param sz The size hint or -1 for no hint.

132

* @return The preferred width.

133

*/

134

public final int getPreferredWidth(int sz);

135

136

/**

137

* Returns the maximum height for the specified width.

138

* @param sz The size hint or -1 for no hint.

139

* @return The maximum height or Integer.MAX_VALUE if not set.

140

*/

141

public final int getMaximumHeight(int sz);

142

143

/**

144

* Returns the maximum width for the specified height.

145

* @param sz The size hint or -1 for no hint.

146

* @return The maximum width or Integer.MAX_VALUE if not set.

147

*/

148

public final int getMaximumWidth(int sz);

149

```

150

151

### Component Information Methods

152

153

Methods for getting component metadata and properties.

154

155

```java { .api }

156

/**

157

* Returns the parent container wrapper.

158

* @return The parent container wrapper or null if no parent.

159

*/

160

public final ContainerWrapper getParent();

161

162

/**

163

* Returns the horizontal screen DPI.

164

* @return The horizontal DPI.

165

*/

166

public final int getHorizontalScreenDPI();

167

168

/**

169

* Returns the vertical screen DPI.

170

* @return The vertical DPI.

171

*/

172

public final int getVerticalScreenDPI();

173

174

/**

175

* Returns the screen width.

176

* @return The screen width in pixels.

177

*/

178

public final int getScreenWidth();

179

180

/**

181

* Returns the screen height.

182

* @return The screen height in pixels.

183

*/

184

public final int getScreenHeight();

185

186

/**

187

* Returns if the component has a baseline.

188

* @return True if the component has a baseline.

189

*/

190

public final boolean hasBaseline();

191

192

/**

193

* Returns the component name for linking.

194

* @return The component name or null.

195

*/

196

public final String getLinkId();

197

198

/**

199

* Returns the visual padding array.

200

* @return Visual padding as [top, left, bottom, right] or null if none.

201

*/

202

public final int[] getVisualPadding();

203

204

/**

205

* Returns the component type constant.

206

* @param disregardScrollPane If scroll panes should be disregarded.

207

* @return The component type constant.

208

*/

209

public int getComponentType(boolean disregardScrollPane);

210

211

/**

212

* Returns the layout hash code.

213

* @return Hash code for layout calculations.

214

*/

215

public int getLayoutHashCode();

216

217

/**

218

* Returns the content bias direction.

219

* @return The content bias or -1 if none.

220

*/

221

public int getContentBias();

222

```

223

224

### Debug and Visualization

225

226

Methods for debug visualization and layout troubleshooting.

227

228

```java { .api }

229

/**

230

* Paints debug outline around the component.

231

* @param showVisualPadding Whether to show visual padding outline.

232

*/

233

public final void paintDebugOutline(boolean showVisualPadding);

234

```

235

236

### SwingContainerWrapper

237

238

Specialized wrapper for Swing Container components extending SwingComponentWrapper functionality.

239

240

```java { .api }

241

/**

242

* Container wrapper for Swing containers.

243

* Extends SwingComponentWrapper and implements ContainerWrapper.

244

*/

245

public final class SwingContainerWrapper extends SwingComponentWrapper implements ContainerWrapper {

246

247

/**

248

* Creates wrapper for Container.

249

* @param c The Swing container to wrap.

250

*/

251

public SwingContainerWrapper(Container c);

252

253

/**

254

* Returns wrapped child components.

255

* @return Array of ComponentWrapper instances for child components.

256

*/

257

public ComponentWrapper[] getComponents();

258

259

/**

260

* Returns the number of child components.

261

* @return The component count.

262

*/

263

public int getComponentCount();

264

265

/**

266

* Returns the container's layout manager.

267

* @return The layout manager object.

268

*/

269

public Object getLayout();

270

271

/**

272

* Returns the component orientation.

273

* @return True if left-to-right orientation.

274

*/

275

public final boolean isLeftToRight();

276

277

/**

278

* Paints debug cell outline for layout debugging.

279

* @param x The x coordinate of the cell.

280

* @param y The y coordinate of the cell.

281

* @param width The width of the cell.

282

* @param height The height of the cell.

283

*/

284

public final void paintDebugCell(int x, int y, int width, int height);

285

286

/**

287

* Returns the component type constant.

288

* @param disregardScrollPane If scroll panes should be disregarded.

289

* @return Always returns TYPE_CONTAINER.

290

*/

291

public int getComponentType(boolean disregardScrollPane);

292

293

/**

294

* Returns the layout hash code.

295

* @return Hash code for layout calculations.

296

*/

297

public int getLayoutHashCode();

298

}

299

```

300

301

### Static Configuration Methods

302

303

Static methods for configuring wrapper behavior globally.

304

305

```java { .api }

306

/**

307

* Returns if visual padding is enabled globally.

308

* @return True if visual padding is enabled.

309

*/

310

public static boolean isVisualPaddingEnabled();

311

312

/**

313

* Sets visual padding enabled state globally.

314

* @param b True to enable visual padding.

315

*/

316

public static void setVisualPaddingEnabled(boolean b);

317

318

/**

319

* @deprecated Java 1.4 is not supported anymore

320

* Returns if maximum size is set on Java 1.4.

321

* @return True if maximum size is set.

322

*/

323

@Deprecated

324

public static boolean isMaxSizeSetOn1_4();

325

326

/**

327

* @deprecated Java 1.4 is not supported anymore

328

* Sets maximum size behavior on Java 1.4.

329

* @param b True to set maximum size.

330

*/

331

@Deprecated

332

public static void setMaxSizeSetOn1_4(boolean b);

333

```

334

335

### Component Type Constants

336

337

Constants for identifying different component types returned by getComponentType().

338

339

```java { .api }

340

// Component type constants

341

public static final int TYPE_UNSET = -1;

342

public static final int TYPE_UNKNOWN = 0;

343

public static final int TYPE_CONTAINER = 1;

344

public static final int TYPE_LABEL = 2;

345

public static final int TYPE_TEXT_FIELD = 3;

346

public static final int TYPE_TEXT_AREA = 4;

347

public static final int TYPE_BUTTON = 5;

348

public static final int TYPE_LIST = 6;

349

public static final int TYPE_TABLE = 7;

350

public static final int TYPE_SCROLL_PANE = 8;

351

public static final int TYPE_IMAGE = 9;

352

public static final int TYPE_PANEL = 10;

353

public static final int TYPE_COMBO_BOX = 11;

354

public static final int TYPE_SLIDER = 12;

355

public static final int TYPE_SPINNER = 13;

356

public static final int TYPE_PROGRESS_BAR = 14;

357

public static final int TYPE_TREE = 15;

358

public static final int TYPE_CHECK_BOX = 16;

359

public static final int TYPE_SCROLL_BAR = 17;

360

public static final int TYPE_SEPARATOR = 18;

361

public static final int TYPE_TABBED_PANE = 19;

362

```

363

364

**Usage Examples:**

365

366

```java

367

import net.miginfocom.swing.*;

368

import javax.swing.*;

369

import java.awt.*;

370

371

// Direct wrapper usage (typically internal to MigLayout)

372

JButton button = new JButton("Test");

373

SwingComponentWrapper wrapper = new SwingComponentWrapper(button);

374

375

// Get component information

376

int baseline = wrapper.getBaseline(100, 30);

377

boolean hasBaseline = wrapper.hasBaseline();

378

int componentType = wrapper.getComponentType(false);

379

380

// Container wrapper usage

381

JPanel panel = new JPanel();

382

SwingContainerWrapper containerWrapper = new SwingContainerWrapper(panel);

383

384

// Get child components

385

ComponentWrapper[] children = containerWrapper.getComponents();

386

int childCount = containerWrapper.getComponentCount();

387

boolean isLTR = containerWrapper.isLeftToRight();

388

389

// Global visual padding configuration

390

SwingComponentWrapper.setVisualPaddingEnabled(true);

391

if (SwingComponentWrapper.isVisualPaddingEnabled()) {

392

// Visual padding is enabled

393

int[] padding = wrapper.getVisualPadding();

394

}

395

396

// Component type identification using constants

397

int componentType = wrapper.getComponentType(false);

398

if (componentType == SwingComponentWrapper.TYPE_BUTTON) {

399

// Handle button-specific logic

400

} else if (componentType == SwingComponentWrapper.TYPE_TEXT_FIELD) {

401

// Handle text field-specific logic

402

} else if (componentType == SwingComponentWrapper.TYPE_CONTAINER) {

403

// Handle container-specific logic

404

}

405

406

// Debug visualization

407

wrapper.paintDebugOutline(true);

408

containerWrapper.paintDebugCell(10, 10, 100, 30);

409

```